package com.hodanet.push;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.WindowManager;

import com.umeng.message.UmengNotificationClickHandler;
import com.umeng.message.UmengNotifyClickActivity;
import com.umeng.message.entity.UMessage;

import org.android.agoo.common.AgooConstants;
import org.json.JSONObject;

public class PushActivity extends UmengNotifyClickActivity {

    private static String TAG = PushActivity.class.getName();


    @Override
    protected void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
    }

    @Override
    public void onMessage(Intent intent) {
        super.onMessage(intent);  //此方法必须调用，否则无法统计打开数
        String body = intent.getStringExtra(AgooConstants.MESSAGE_BODY);
        Log.i(TAG, body);
        try {
            JSONObject umengJson = new JSONObject(body);
            UMessage uMessage = new UMessage(umengJson);
            uMessage.clickOrDismiss = true;
            UmengNotificationClickHandler umengNotificationClickHandler = new UmengNotificationClickHandler();
            umengNotificationClickHandler.handleMessage(this, uMessage);
            finish();
        } catch (Exception e) {
            Log.i(TAG, e.getMessage());
            finish();
        }
    }
}
